package login

import (
	"context"
	v1 "donkey-admin/api/user/v1"
	"donkey-admin/internal/dao"
	"donkey-admin/utility"
	"github.com/gogf/gf/v2/errors/gerror"
	"github.com/gogf/gf/v2/frame/g"
)

func (s *sUser) UserPasswordReset(ctx context.Context, req *v1.UserPasswordResetReq) (res *v1.UserPasswordResetRes, err error) {

	defaultPasswd, err := g.Config().Get(ctx, "user.defaultPasswd")
	if err != nil {
		g.Log().Error(ctx, err)
		return nil, gerror.New("密码重置失败")
	}
	_, err = dao.SysUser.Ctx(ctx).Update(g.Map{"user_passwd": utility.BcryptHash(defaultPasswd.String())}, "uuid", req.UserUuid)
	if err != nil {
		g.Log().Error(ctx, err)
		return nil, gerror.New("密码重置失败")
	}

	return &v1.UserPasswordResetRes{
		Passwd: defaultPasswd.String(),
	}, nil
}
